/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tabelamodelcolumnmodel.obrigacoes;

import java.awt.FontMetrics;
import javax.swing.table.DefaultTableColumnModel;
import javax.swing.table.TableColumn;
import utilitarios.MyCellRenderer;

/**
 *
 * @author Icaro
 */
public class VersaoSpedFiscalColumnModel extends DefaultTableColumnModel {

    private TableColumn criaColuna(int columnIndex, int largura,
            FontMetrics fm, boolean resizeable, String titulo) {
        int larguraTitulo = fm.stringWidth(titulo + " ");

        if (largura < larguraTitulo) {
            largura = larguraTitulo;
        }

        TableColumn col = new TableColumn(columnIndex);

        col.setCellRenderer(new MyCellRenderer());
        col.setHeaderRenderer(null);
        col.setHeaderValue(titulo);
        col.setPreferredWidth(largura);

        if (!resizeable) {
            col.setMaxWidth(largura);
            col.setMinWidth(largura);
        }

        col.setResizable(resizeable);

        return col;
    }

    /**
     * Creates a new instance of TarefasColumnModel
     */
    public VersaoSpedFiscalColumnModel(FontMetrics fm) {
        int digito = fm.stringWidth("0");
        int letra = fm.stringWidth("M");
        addColumn(criaColuna(0, 64 * letra, fm, false, "Versão"));
        addColumn(criaColuna(1, 20 * digito, fm, false, "Descricão"));
        addColumn(criaColuna(2, 20 * digito, fm, false, "Data Validade"));
    }
}
